<% tasks.each do |task| %>
<div id="feed_task_<%= task.id %>" class='task feed_task_<%= task.id %>'>
  <div class='left'>
    <%= check_box_tag 'id', 
          task.id,
          task.status.completed?,
          :id => "link_to_task_#{task.id}_completed_#{cycle 'left','right', :name => "task_#{task.id}"}",
          :title => task.status.completed? ? '已完成' : '未完成'
        %>
    <script>
      $('#link_to_task_<%= task.id %>_completed_<%= current_cycle "task_#{task.id}" %>').click(function() {
        $.ajax({
          url: "<%= task.status.completed? ? waiting_task_url(task) : completed_task_url(task) %>",
          type: 'POST',
          data: {
            _method:'PUT'
          },
          beforeSend: function(){
            $('#feed_task_<%= task.id %>').addClass('mark_task_completed');
            $('#feed_task_<%= task.id %>').attr("readonly",true);
            $('.feed_task_<%= task.id %>').each(function() {              
              $(this).hide('slow');
            });
          }
        });
      });
    </script>
  </div>
  <div class='right'>
    <b class='type <%= task_type_class_name task.type_name %>'><%= task.type_name%></b>
    <span class='c'><%= task.name%></span>
    <% if task.order_item.present? %>
    <span class='r'>
      (来源：
      <%if task.order_item.order.present?%>
    <%= link_to truncate("#{task.order_item.order.buyer_full_name},#{task.order_item.order.buyer_address}",:length => 14),
                          order_url(task.order_item.order),
                          :title => "订单:#{task.order_item.order.buyer_full_name}-#{task.order_item.order.buyer_phone}-#{task.order_item.order.buyer_address},预订【#{task.order_item.furniture_code}:#{task.order_item.furniture_name}】#{task.order_item.ordered_count}件",
                          :class => 'from_order_item',
                          :target => :_blank %>
      <%else%>
       您无权看到此单据，请联系管理员解决
      <%end%>)
    </span>
    <%end%>
    <% if not task.assigned_by_and_to_current_user?  %>
      <span class="assign" title="<%= "#{task.initiator.nick_name}于#{time_ago_in_words(task.created_at, false)}前指派给#{task.executor.nick_name}" %>">
     <%= link_to task.initiator.nick_name,
            user_url(task.initiator.full_name),
            :target => :_blank  if not task.assigned_by_current_user?
      %>
     <%= image_tag 'tasks/assigned_to.png', :title => '指派', :alt => '指派' %>
     <%= link_to task.executor.nick_name,
          user_url(task.executor.nick_name),
          :target => :_blank if not task.assigned_to_current_user?
       %>
     </span>
    <% end %>
    <% if task.allow_to_be_edited_or_destroyed? %>    
      <% if params[:controller] == 'orders' %>
      <span class='t'>
      <%= link_to '编辑', edit_task_order_url(task),
                   :method => :get,
                   :remote => true,
                   :title => '编辑该任务' %>
      <%= link_to '删除', destroy_task_order_url(task),
                   :method => :delete,
                   :confirm => "确定要删除该任务吗？",
                   :remote => true,
                   :title => '删除该任务' %>
      
      </span>
      <%elsif params[:controller] == 'tasks' %>
      <span class='t'>
      <%= link_to '编辑', edit_task_url(task) + "?type=#{params[:type]}",
                   :method => :get,
                   :remote => true,
                   :title => '编辑该任务' %>
      <%= link_to '删除', task_url(task) + "?type=#{params[:type]}",
                   :method => :delete,
                   :confirm => "确定要删除该任务吗？",
                   :remote => true,
                   :title => '删除该任务' %>
      
      </span>
      <%end%>
    <% end %>
  </div>
</div>
<%end%>